package com.cy.pj.common.util;

import com.cy.pj.common.utils.ServletUtils;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;

import javax.servlet.http.HttpServletRequest;

public class PageUtil {
    /**
     * 通过此方法启动分页查询
     * @param <T> 这里的T为泛型,返回值类型左侧有<T>这种符号的表示方法为泛型方法
     */
    public static <T>Page<T> startPage(){
        HttpServletRequest request = ServletUtils.getRequest();
        //页面大小
        String pageSizeStr = request.getParameter("pageSize");
        //当前页码值
        String pageCurrentStr = request.getParameter("pageCurrent");
        System.out.println("pageSize="+pageSizeStr);
        System.out.println("pageCurrent="+pageCurrentStr);

        Integer pageCurrent = StringUtil.isEmpty(pageCurrentStr)?1:Integer.parseInt(pageCurrentStr);
        Integer pageSize = StringUtil.isEmpty(pageSizeStr)?5:Integer.parseInt(pageSizeStr);
        return PageHelper.startPage(pageCurrent,pageSize);
    }
}
